package com.example.demo.controller;


import com.example.demo.annoation.Log;
import com.example.demo.bean.AjaxRes;
import com.example.demo.bean.SysJob;
import com.example.demo.bean.SysJobLog;
import com.example.demo.dto.task.SysJobLogPageReqVO;
import com.example.demo.dto.task.SysJobPageReqVO;
import com.example.demo.enums.BusinessType;
import com.example.demo.exception.TaskException;
import com.example.demo.service.ISysJobLogService;
import com.example.demo.service.ISysJobService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.quartz.SchedulerException;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RequestMapping(value = "/monitor/sys_job_log")
@RestController
public class SysJobLogController extends BaseAdminController {

    @Resource
    private ISysJobLogService sysJobLogService;

    @GetMapping(value = "/list")
    public AjaxRes list(SysJobLogPageReqVO sysJobPageReqVO) {
        return AjaxRes.success(sysJobLogService.list(sysJobPageReqVO));
    }

    @GetMapping("/{jobLogId}")
    public AjaxRes query(@PathVariable("jobLogId") Long jobLogId) {
        return AjaxRes.success(sysJobLogService.getSysJobLog(new SysJobLog().setJobLogId(jobLogId)));
    }

    @DeleteMapping("/delete/{jobLogIds}")
    @Log(title = "删除任务调度日志", businessType = BusinessType.DELETE)
    public AjaxRes delete(@PathVariable("jobLogIds") Long[] jobLogIds) {
        return toAjax(sysJobLogService.deleteSysJobLog(jobLogIds));
    }

    @DeleteMapping("/clear")
    @Log(title = "清空任务调度日志", businessType = BusinessType.CLEAR)
    public AjaxRes clear(){
        sysJobLogService.clearSysJobLog();
        return success();
    }
}
